package com.muyu.user.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.common.core.web.page.PageQueryModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.user.mapper.SysUserCouponMapper;
import com.muyu.user.domain.SysUserCoupon;
import com.muyu.user.domain.model.SysUserCouponQueryModel;
import com.muyu.user.domain.model.SysUserCouponPageQueryModel;
import com.muyu.user.service.SysUserCouponService;

/**
 * 用户优惠券记录Service业务层处理
 *
 * @author liuguoqiang
 * @date 2025-09-18
 */
@Slf4j
@Service
public class SysUserCouponServiceImpl extends ServiceImpl<SysUserCouponMapper, SysUserCoupon>  implements SysUserCouponService {

    /**
     * 查询用户优惠券记录列表
     *
     * @param pageQueryModel 用户优惠券记录
     * @return 用户优惠券记录
     */
    @Override
    public PageQueryModel<SysUserCouponPageQueryModel> pageQuery(SysUserCouponQueryModel pageQueryModel) {
        LambdaQueryWrapper<SysUserCoupon> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.like(ObjectUtil.isNotNull(pageQueryModel.getCouponName()),SysUserCoupon::getCouponName, pageQueryModel.getCouponName());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getFaceValue()), SysUserCoupon::getFaceValue, pageQueryModel.getFaceValue());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getMinAmount()), SysUserCoupon::getMinAmount, pageQueryModel.getMinAmount());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getExpireTime()), SysUserCoupon::getExpireTime, pageQueryModel.getExpireTime());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getExchangeTime()), SysUserCoupon::getExchangeTime, pageQueryModel.getExchangeTime());
       Page<SysUserCoupon> page = this.page(pageQueryModel.buildPage(), queryWrapper);
        return PageQueryModel.of(page).cover(SysUserCouponPageQueryModel::infoBuild);
    }

}
